package com.ai.module.business.service.impl;

import com.ai.module.business.domain.entity.CommentRecordEntity;
import com.ai.module.business.domain.req.CommentRecordReq;
import com.ai.module.business.mapper.CommentRecordMapper;
import com.ai.module.business.service.CommentRecordService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author: MrHe
 * @create: 2024-01-25 02:07
 * @description:
 **/
@Service
public class CommentRecordServiceImpl  extends ServiceImpl<CommentRecordMapper, CommentRecordEntity> implements CommentRecordService {

    @Override
    public Page<CommentRecordEntity> findRecords(CommentRecordReq commentRecordReq) {
         Page<CommentRecordEntity> page = new Page<>(commentRecordReq.getPage(), commentRecordReq.getSize());
        return  this.page(page,
                new LambdaQueryWrapper<CommentRecordEntity>()
                        .eq(CommentRecordEntity::getBusinessId,commentRecordReq.getBusinessId())
                        .eq(CommentRecordEntity::getBusinessType,commentRecordReq.getBusinessType())
        );
    }

    @Override
    public void saveComment(CommentRecordReq commentRecordReq) {

        CommentRecordEntity commentRecord = new CommentRecordEntity();
        BeanUtils.copyProperties(commentRecordReq,commentRecord);
        this.save(commentRecord);
    }
}
